package com.kanshu.ksgb.fastread.doudou.base.baseui;

import android.app.Activity;
import android.util.Log;
import android.webkit.JavascriptInterface;

import com.kanshu.ksgb.fastread.doudou.common.urlrouter.UrlRouter;
import com.kanshu.ksgb.fastread.doudou.module.personal.bean.BindInfo;
import com.kanshu.ksgb.fastread.doudou.common.business.utils.UserUtils;

import org.greenrobot.eventbus.EventBus;

import static com.bumptech.glide.Glide.with;

/**
 * Created by wcy on 2017\7\19 0019.
 */

public class JsBridge {
    private Activity mActivity;

    public JsBridge(Activity activity) {
        mActivity = activity;
    }

    /**
     * 统一跳转方案
     *
     * @param url
     */
    @JavascriptInterface
    public void jump(String url) {
        if (mActivity.isFinishing()) {
            return;
        }
        Log.d("wcy", "url=" + url);
        // 跳转逻辑
        UrlRouter.from(mActivity).jump(url);
    }
    /**
     * 退出当前页面
     */
    @JavascriptInterface
    public void exit() {
        if (mActivity.isFinishing()) {
            return;
        }
        mActivity.finish();
    }


    /**
     *  获取用户id
     */
    @JavascriptInterface
    public String getUserId() {
        return UserUtils.getUserId();
    }

    /**
     * 刷新个人中心的数据
     */
    @JavascriptInterface
    public void refreshPersonCenter() {
        BindInfo bindInfo = new BindInfo();
        bindInfo.result = true;
        EventBus.getDefault().post(bindInfo);
    }

}
